NVM.FiveBar = (function () {
    var __core = NOVEM.Core;

    var _scroll = function (element) {
        var body = __core.getVars.elBody.classList;

        var elMobile = element.getAttribute("data-mobile") || "false",
            elOffset = element.getAttribute("data-offset") || 450;

        if (
            elMobile == "false" &&
            (body.contains("device-xs") ||
                body.contains("device-sm") ||
                body.contains("device-md"))
        ) {
            return true;
        }

        (document.body.scrollTop || document.documentElement.scrollTop) <= elOffset
            ? element.classList.add("opacity-0")
            : element.classList.remove("opacity-0");

        if (window.scrollY > Number(elOffset)) {
            body.add("fivebar-active");
        } else {
            body.remove("fivebar-active");
        }
    };

    return {
        init: function (selector) {
            selector = __core.getSelector(selector, false);
            if (selector.length < 1) {
                return true;
            }

            // _init(selector[0]);
            _scroll(selector[0]);

            window.addEventListener(
                "scroll",
                function () {
                    _scroll(selector[0]);
                },
                { passive: true }
            );
        },
    };
})();
